package webserver

import (
	"GoDance/webserver/Email"
	"GoDance/webserver/idxopt"
	myjwt "GoDance/webserver/jwt"
	"GoDance/webserver/mysql"
	Redis "GoDance/webserver/redis"
	"GoDance/webserver/websearch"
	"github.com/gin-contrib/pprof"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Register(r *gin.Engine) {

	r.Static("/godance", "./webserver/View_final/src")
	r.LoadHTMLFiles("webserver/View_final/index.html", "webserver/View_final/indexPicture.html")

	//打开index页面
	r.GET("/index", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index.html", nil)
	})

	//打开index页面
	r.GET("/indexPicture", func(c *gin.Context) {
		c.HTML(http.StatusOK, "indexPicture.html", nil)
	})

	//注册
	r.POST("/godance/register", mysql.Register())

	//登录
	r.POST("/godance/sign", mysql.Sign())
	//销户
	r.POST("/godance/delete", mysql.Delete())
	//邮箱
	r.POST("/godance/get_code", Email.SendEmail())

	//测试jwt
	r.POST("/test", myjwt.JWTAuthMiddleware(), func(c *gin.Context) {
		username, _ := c.Get("userId")

		c.JSON(http.StatusOK, gin.H{
			"token": username,
			"code":  200,
		})
	})

	//获取所有收藏夹的名称
	r.GET("/collection", myjwt.JWTAuthMiddleware(), Redis.Get_Collection_final())
	//获取指定收藏夹的内容
	r.GET("/bag_child", myjwt.JWTAuthMiddleware(), Redis.Get_Bag_Child())
	//添加收藏夹
	r.POST("/godance/add_one", myjwt.JWTAuthMiddleware(), Redis.Add_collection())
	//删除收藏夹
	r.POST("/godance/delete_one", myjwt.JWTAuthMiddleware(), Redis.Delete_collection())
	//增加收藏夹内容
	r.POST("/godance/add_one_child", myjwt.JWTAuthMiddleware(), Redis.Add_child())
	//删除收藏夹内容
	r.POST("/godance/delete_one_child", myjwt.JWTAuthMiddleware(), Redis.Delete_child())
	//判断某个id在收藏夹中是否存在
	r.POST("/godance/is_not", myjwt.JWTAuthMiddleware(), Redis.Is_not())

	// 对索引的操作
	r.POST("/create", idxopt.CreateIndex())

	// 对文档的操作
	r.POST("/update", idxopt.AddDocument())
	r.DELETE("/update", idxopt.DeleteDocument())
	r.PUT("/update", idxopt.UpdateDocument())

	//搜索方面
	r.GET("/search_text", websearch.Get_relation())
	r.GET("/search_final", websearch.Get_related())
	r.POST("/godance/get_essay", websearch.Get_essay())

	// 搜索相关的API
	r.GET("/search_related_image", websearch.Get_relation_image())
	r.GET("/search_result_image", websearch.Get_related_image())

	// 获取文档
	r.POST("/get_doc_image", websearch.Get_essay_image())

	pprof.Register(r)

}
